// 下载App
function app(){
	var download = document.getElementsByClassName("download")[0];
	var down = document.getElementsByClassName("down-box")[0];
	var triangle = document.getElementById("triangle");
	download.onmouseover = function(){
		down.style.height = 130 + "px";
		triangle.style.display = "block";
	}
	download.onmouseout = function(){
		down.style.height = 0;
		triangle.style.display = "none";
	}
}
app();
// // 购物车
function shop(){
	var car = document.getElementsByClassName("car-box")[0];
	var pop = document.getElementsByClassName("pop")[0];
	car.onmouseover = function(){
		pop.style.height = 90 + "px";
	}
	car.onmouseout = function(){
		pop.style.height = 0;
	}
}
shop();
// 购物车旁边
//删除
//选项卡
var pops = document.querySelectorAll(".pops");
	navItem = document.querySelectorAll(".nav-item");
for(var i = 1;i < navItem.length;i++){
	navItem[i].index = i;
	navItem[i].onmouseover = function(){
		for(var i = 0;i < pops.length;i++){
			pops[i].style.display = "none";
		}
		pops[this.index - 1].style.display = "block";
		searchInput.blur();
		pops[this.index - 1].style.borderTop = "1px solid #e0e0e0";
		pops[this.index - 1].classList.add("menuHeight");
	}
	navItem[i].onmouseout = function(){
		pops[this.index - 1].classList.remove("menuHeight");
		pops[this.index - 1].style.border = "none";
	}
}
for(var j = 0;j < pops.length;j++){
	pops[j].onmouseover = function(){
		this.style.borderTop = "1px solid #e0e0e0";
		this.classList.add("menuHeight");
	}
	pops[j].onmouseout = function(){
		this.style.border = "none";
		this.classList.remove("menuHeight");
	}
}
// 全部分类选项卡
var tab = document.getElementsByClassName("tab");
var children = document.getElementsByClassName("children");
for(var m = 0;m < tab.length;m++){
	tab[m].index =m;
	tab[m].onmouseover =function(){
		for(var j = 0;j < children.length;j++){
			children[this.index].style.display = "block";
			searchInput.blur();
		}
	}
	tab[m].onmouseout =function(){
		for(var j = 0;j < children.length;j++){
			children[this.index].style.display = "none";
		}
	}
}
for(var j = 0;j < children.length;j++){
	children[j].onmouseover = function(){
		this.style.display = "block";
		
	}
	children[j].onmouseout = function(){
		this.style.display = "none";
	}
}
// 搜索框
var searchInput = document.getElementById("search-input");
// 轮播图
change();
function change() {
	var index = 0;
	var timer;
	var silde = document.getElementsByClassName("slide");
	var bullet = document.getElementsByClassName("bullet");
	var swiper = document.getElementsByClassName("swiper")[0];
	var prev = document.getElementsByClassName("prev")[0];
	var next = document.getElementsByClassName("next")[0];
	var size = silde.length;
	// 开启自动轮播
	swiper.onmouseover = function(){
		clearInterval(timer);
	}
	function prevplay(){
		prev.onclick = function(){
			clearInterval(timer);
			index--;
			if(index < 0){
				index = 4;
			}
			for(var k = 0;k < size;k++){
				if(index != k){
					silde[k].style.opacity = 0;
					bullet[k].classList.remove("active");
					bullet[k].style.transform = "scale(1)";
				}
			}
			bullet[index].classList.add("active");
			bullet[index].style.transform = "scale(1.5)";
			silde[index].style.opacity = 1;
			startAutoPlay();
		}
	}
	function nextplay(){
		next.onclick = function(){
			clearInterval(timer);
			index++;
			if(index >= size){
				index = 0;
			}
			for(var k = 0;k < size;k++){
				if(index != k){
					silde[k].style.opacity = 0;
					bullet[k].classList.remove("active");
					bullet[k].style.transform = "scale(1)";
				}
			}
			silde[index].style.opacity = 1;
			bullet[index].classList.add("active");
			bullet[index].style.transform = "scale(1.5)";
			startAutoPlay();
		}
	}
	function btnplay(){
		for(var j = 0;j < bullet.length;j++){
			bullet[j].index = j;
			bullet[j].onclick = function(){
				clearInterval(timer);
				index = this.index;
				silde[index].style.opacity = 1;
				bullet[index].classList.add("active");
				bullet[index].style.transform = "scale(1.5)";
				for(var m = 0; m < bullet.length; m++) {
					if(index != m) {
						silde[m].style.opacity = 0;
						bullet[m].classList.remove("active");
						bullet[m].style.transform = "scale(1)";
					}	
				}
				startAutoPlay();
			}
		}
	}
	function startAutoPlay(){
		 timer = setInterval(function(){
			index++;
			for(var i = 0;i<size;i++){
				silde[i].style.opacity = 0;
				bullet[i].classList.remove("active");
				bullet[i].style.transform = "scale(1)";
			}
			if(index >= size) index = 0;
			silde[index].style.opacity = 1;
			bullet[index].classList.add("active");
			bullet[index].style.transform = "scale(1.5)";
		},3000)
	}
	startAutoPlay();
	btnplay();
	prevplay();
	nextplay();
}

// 选项卡的封装函数
// tabList(navItem, pops, 1, 2);
// tabList(tab, children,0,0);
// function tabList(obj, obj2,number, number2) {
// 	for(var m = number;m < obj.length - number2;m++){
// 		obj[m].index = m;
// 		obj[m].onmouseover =function(){
// 			for(var j = 0;j < obj2.length;j++){
// 				obj2[this.index - number].style.display = "block";
// 			}
// 		}
// 		obj[m].onmouseout =function(){
// 			for(var j = 0;j < obj2.length;j++){
// 				obj2[this.index - number].style.display = "none";
// 			}
// 		}
// 	}
// 	for(var j = 0;j < obj2.length;j++){
// 		obj2[j].onmouseover = function(){
// 			this.style.display = "block";
			
// 		}
// 		obj2[j].onmouseout = function(){
// 			this.style.display = "none";
// 		}
// 	}
// }